package com.elitel.frame.base.controller;

import com.elitel.frame.base.service.AcServiceFilterFieldService;
import com.elitel.frame.main.entity.vo.AcServiceFilterFieldFormVo;
import com.elitel.frame.main.entity.vo.AcServiceFilterFieldVo;
import com.elitel.frame.main.entity.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 *  过滤字段
 *  @author hi_bj
 */
@RequestMapping("/accesscontrol/filterfield")
@Controller
public class AcServiceFilterFieldController {
    @Autowired
    private AcServiceFilterFieldService acServiceFilterFieldService;

    /**
     * 获取数据（过滤字段列）
     * @param serviceCode
     * @return
     */
    @RequestMapping("/getDataList")
    @ResponseBody
    public JsonResult getDataList(@RequestBody String serviceCode) {
        JsonResult jsonResult = new JsonResult();
        List<AcServiceFilterFieldVo> resById = acServiceFilterFieldService.getDataList(serviceCode);
        jsonResult.setData(resById);
        jsonResult.setSuccess(true);
        return jsonResult;
    }
    
    /**
     * 获取数据（过滤字段列）
     * @param params
     * @return
     */
    @RequestMapping("/getFieldDataList")
    @ResponseBody
    public JsonResult getFieldDataList(@RequestBody Map<String,String> params) {
        
        try {
            return getDataList(params.get("serviceCode"));
        } catch (Exception e) {
            e.printStackTrace();
            JsonResult jsonResult = new JsonResult();
            jsonResult.setSuccess(false);
            return jsonResult;
        }
    }
    /**
     * 添加
     * @param acServiceFilterFieldVo
     * @return JsonResult
     */
    @RequestMapping("/save")
    @ResponseBody
    public Object insert(@RequestBody AcServiceFilterFieldFormVo acServiceFilterFieldVo) {
        JsonResult jr = new JsonResult();
        int result = acServiceFilterFieldService.insert(acServiceFilterFieldVo);
        jr.setSuccess(result >= 0 ? true : false);
        jr.setData(result);
        return jr;
    }


}
